package com.alliky.user.ui.activity;

import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alliky.core.base.BaseActivity;
import com.alliky.core.router.RoutePath;
import com.alliky.user.BR;
import com.alliky.user.R;
import com.alliky.user.databinding.ActivityLoginBinding;
import com.alliky.user.ui.viewmodel.LoginViewModel;

@Route(path = RoutePath.User.ACTIVITY_LOGIN)
public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewModel> {
    //ActivityLoginBinding类是databinding框架自定生成的,对应activity_login.xml
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_login;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initViewObservable() {
        //监听ViewModel中pSwitchObservable的变化, 当ViewModel中执行【uc.pSwitchObservable.set(!uc.pSwitchObservable.get());】时会回调该方法
        mViewModel.uc.pSwitchEvent.observe(this, aBoolean -> {
            //pSwitchObservable是boolean类型的观察者,所以可以直接使用它的值改变密码开关的图标
            if (mViewModel.uc.pSwitchEvent.getValue()) {
                //密码可见
                //在xml中定义id后,使用binding可以直接拿到这个view的引用,不再需要findViewById去找控件了
                binding.ivSwichPasswrod.setImageResource(R.mipmap.show_psw_press);
                binding.etPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            } else {
                //密码不可见
                binding.ivSwichPasswrod.setImageResource(R.mipmap.show_psw);
                binding.etPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
        });

        mViewModel.uc.mUserVOSingleLiveEvent.observe(this, userVO -> {
            if (userVO != null) {

            }
        });
    }
}